package com.css.zfzx.fwsjcj.modules.expert.respository;

import com.css.zfzx.fwsjcj.modules.expert.entity.FwUserDivisionEntity;
import com.css.zfzx.fwsjcj.modules.expert.vo.FwUserDivisionVo;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.data.repository.query.Param;
import java.util.List;
import java.util.Map;

@Repository
public interface FwUserDivisionRespository extends JpaRepository<FwUserDivisionEntity,String> {

    @Transactional
    @Modifying
    @Query(
            value = "delete from fw_user_division where user_id= :userId",nativeQuery = true
    )
    void del(@Param("userId") String userId);

    @Query(nativeQuery = true,value = "select division_id divisionId,division_name divisionName from fw_user_division  where division_level=1 and user_id=:userId order by division_code")
    List<Map<String,Object>> getProvince(@Param("userId")String userId);

    @Query(nativeQuery = true,value = "select division_id divisionId,division_name divisionName from fw_user_division  where division_level=2 and user_id=:userId order by division_code")
    List<Map<String, Object>> getCity(@Param("userId")String userId);

    @Query(nativeQuery = true,value = "select division_id divisionId,division_name divisionName from fw_user_division  where user_id=:userId and parent_id=:provinceId order by division_code")
    List<Map<String,Object>> getProvincialCity(@Param("userId")String userId, @Param("provinceId")String provinceId);

    @Query(nativeQuery = true,value = "select * from fw_user_division  where user_id=:userId")
    List<FwUserDivisionEntity> getDataRange(@Param("userId")String userId);
}
